package com.itheima.algorithm.hashtable;

import java.util.HashMap;
import java.util.HashSet;

/**
 * @author: TylerZhong
 * @description:
 */
public class E04Leetcode217 {
    public static boolean containsDuplicate(int[] nums) {
        HashMap<Integer, Object> map = new HashMap<>();
        Object value = new Object();
        for (int key : nums) {
            Object put = map.put(key, value);
            if (put != null) {
                return true;
            }
        }
        return false;
    }
    public static boolean containsDuplicate2(int[] nums) {
        HashSet<Object> set = new HashSet<>();
        for (int key : nums) {
            if (!set.add(key)) {
             return true;
            }
        }
        return false;
    }
    public static boolean containsDuplicate1(int[] nums) {
        HashMap<Integer, Object> map = new HashMap<>();
        for (int key : nums) {
            if (map.containsKey(key)) {
                return true;
            }
            map.put(key, key);
        }
        return false;
    }

    public static void main(String[] args) {

    }
}
